﻿
@{
    ViewBag.Title = "我的收藏";
    Layout = "~/Views/Shared/_UserLayout.cshtml";
}
@model UserCollectModel[]
<!--用户中心(收藏)-->
<div class="user_style clearfix" id="user">
    <div class="user_title"><em></em>用户中心</div>
    <div class="clearfix user">
        <!--左侧菜单栏样式-->
        @Html.Partial("~/Views/Shared/_PartialUserLeft.cshtml")
        <!--右侧内容样式-->
        <div class=" right_style r_user_style user_right">
            <div class="user_Borders clearfix">
                <div class="title_name">
                    <span class="name">用户收藏</span>
                </div>
                <!--收藏样式-->
                <div class="Collect">
                    <ul class="Collect_list">
                        @for (int i = 1; i <= Model.Count(); i++)
                        {
                            <li id="@("collect" + i)">
                                <div class="Collect_pro_name">
                                    <a href="javascript:void(0)" id="@Model[i-1].CollectId" class="delete_Collect"></a>
                                    <p class="img center"><a target="_blank" href="~/Home/Detail?goodid=@Model[i-1].Good.Id"><img src="@("http://static.amortal.top/"+Model[i-1].GoodImgSrc+"?imageView2/2/w/200/h/200/interlace/1/q/100")" /></a></p>
                                    <p><a target="_blank" href="~/Home/Detail?goodid=@Model[i-1].Good.Id">@Model[i - 1].Good.Name-@Model[i - 1].Good.CatoryName</a></p>
                                    <p class="Collect_Standard">原始价格:@Model[i - 1].Good.PrePrice</p>
                                    <p class="Collect_price">￥@Model[i - 1].Good.Price</p>
                                </div>
                            </li>
                        }


                    </ul>
                    <div class="pages_Collect">

                        @for (int i = 1; i <= Math.Ceiling(Model.Count() * 1.0 / 6); i++)
                        {
                            if (i == 1)
                            {
                                <a value="@i" href="javascript:void(0)" class="on page_index">@i</a>
                            }
                            else
                            {
                                <a value="@i" href="javascript:void(0)" class="page_index">@i</a>
                            }

                        }

                    </div>
                    <div class="us_jls">&nbsp;&nbsp;&nbsp; 共 @Model.Count() 条记录</div>
                </div>
            </div>
        </div>
    </div>
</div>
@section FooterScript{
    <script src="~/common/Threelinkage/layui/layui.all.js"></script>
    <script type="text/javascript">

        layui.config({
            base: "js/"
        }).use(['layer'], function () {
            var layer = parent.layer === undefined ? layui.layer : parent.layer;


            $(".delete_Collect").click(function () {

                var id = $(this).attr("id");

                layer.confirm('确定取消收藏？', { icon: 3, title: '提示信息' }, function (index) {
                    
                    var index = layer.msg('删除中，请稍候', { icon: 16, time: false, shade: 0.8 });
                    $.ajax({
                        url: "/User/CollectDelete",
                        type: "post",
                        dataType: "json",
                        data: { "collectId": id },
                        success: function (res) {
                            layer.close(index);
                            if (res.status == "ok") {
                                layer.msg("删除成功", {
                                    icon: 1, time: 2000, end: function () {
                                        layer.msg("正在刷新页面...");
                                        location.reload();
                                    }
                                });



                            } else {
                                layer.msg("删除失败", {
                                    icon: 5, time: 2000, end: function () {
                                        location.reload();
                                    }
                                });
                            }
                        },
                        error: function () {
                            layer.msg("网络请求失败", {
                                icon: 5, time: 2000, end: function () {
                                    location.reload();
                                }
                            });
                        }
                    });
                })



            });

        });

        $(function () {
            $(".Collect_list li").hide();

            changeOrderRecord(1);


            $(".pages_Collect a").click(function () {
                $(".pages_Collect a").removeClass("on");
                $(this).addClass("on");
                var index = $(this).attr("value");

                changeOrderRecord(parseInt(index))
            });

            function changeOrderRecord(pageIndex) {

                $(".Collect_list li").hide();

                index = pageIndex * 6

                for (var i = 0; i < 6; i++) {
                    $("#collect" + (index - i)).show();
                }
                //$("#collect" + (index - 1)).show();
                //$("#collect" + index).show();

            }

        });
    </script>
}
